package com.bw.home.adpter

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.PagerAdapter
import com.bw.home.entity.SimpleTypeEntity
import com.bw.home.ui.SimpleTypeFragment


class HomePageAdapter(
    val typeList: List<SimpleTypeEntity>,
    val fragmentManager: FragmentManager
) : FragmentStatePagerAdapter(fragmentManager) {
    private val fragmentList: MutableList<Fragment>

    init {
        fragmentList = mutableListOf()
        for (entity in typeList) {
            val fragment = SimpleTypeFragment()
            val bundle = Bundle()
            bundle.putString("channelId", entity.channelid)
            fragment.arguments = bundle
            fragmentList.add(fragment)
        }
    }

    override fun getCount(): Int {
        return fragmentList.size
    }

    override fun getItem(position: Int): Fragment {
        return fragmentList.get(position)
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return typeList.get(position).typename
    }

    override fun getItemPosition(`object`: Any): Int {
        return PagerAdapter.POSITION_NONE
    }
}